﻿var Date = {
    model: function (d = {}) {
        this.Title = d.Title || "日期";
        this.EnTitle = d.EnTitle || "";
        this.Tips = d.Tips || "";
        this.Name = d.Name || 'lg' + lg.GetSN(6, 10);
        this.Value = d.Value || "";
        this.ExportName = d.ExportName || "";
        this.Width = d.Width || "100%";
        this.Required = d.Required || false;
        this.DateFormat = d.DateFormat || "yyyy-MM-dd";
        this.Range = d.Range || ["", ""];
        this.IsRender = d.IsRender != undefined ? d.IsRender : true;
        this.IsShow = d.IsShow || false;
        this.IsExport = d.IsExport || false;
        this.IsWhere = d.IsWhere || false;
        this.WhereKey = d.WhereKey || "精确匹配"
    },
    component: {
        name: "lg-form-date",
        data: {
            props: {
                items: {
                    type: Array,
                    default: []
                },
                value: {
                    type: [String, Object, Number],
                    default: ""
                },
                data: {
                    type: Object,
                    default: {}
                },
                format: {
                    type: String,
                    default: "date"
                },
                //0填写 1查看
                renderType: {
                    type: Number,
                    default: 0
                }
            },
            mounted: function () {
                var that = this;
                laydate.render({
                    elem: '#' + this.data.Name
                    , type: this.format
                    , done: (value, date, endDate) => {
                        this.$emit("update:value", value)
                        this.$emit("done", this.data)
                    }
                });
            },
            template: `
					   <div :class="['lg-form-item',{'lg-ver-error':data.error},{'pointer-none':renderType==1}]" :style="{'width':data.Width}">
					      <div class="lg-form-block">
						      <div class="lg-form-title">
						  	    <div class="lg-form-title-item">
                        	  	    <i v-if="data.Required">*</i>
			            	  	    <span class="cn">{{data.Title}}</span>
                        	  	    <span class="en">{{data.EnTitle}}</span>
			         	  	    </div>
					  	      </div>
							  <div class="lg-form-control">
							     <input type="text" class="lg-input lg-input-text" :id="data.Name" :value="value" readonly>
							  </div>
					      </div>
						  <div class="lg-form-block">
					          <div class="lg-form-tip"><p>{{data.Tips}}</p></div>
					          <div class="lg-form-ver" v-if="data.error">{{data.errMsg}}</div>
						  </div>
					  </div>`
        }
    }
}

Date.model.prototype.verify = function () {
    var res = { state: true, msg: "ok" };
    if (this.Required) {
        res.state = lg.regx.required(this.Value);
        if (!res.state) {
            res.msg = "必填项不可为空!";
            return res;
        }
    }
    return res
}

export { Date }
